﻿using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Collections.Generic;
using System.Windows.Media.Imaging;

using Cratos.Desktop;

namespace Cratos.Generator
{
	/// <summary>
	/// Cratos Project User Control class
	/// </summary>
	public partial class CratosProjectView : UserControl
	{
		#region Class Constant declarations
		#endregion

		#region Custom Routed Commands
		/// <summary>
		/// Modify command
		/// </summary>
		public static RoutedCommand ModifyCommand = new RoutedCommand();

		/// <summary>
		/// Delete command
		/// </summary>
		public static RoutedCommand DeleteCommand = new RoutedCommand();

		/// <summary>
		/// Save command
		/// </summary>
		public static RoutedCommand SaveCommand = new RoutedCommand();

		/// <summary>
		/// Cancel command
		/// </summary>
		public static RoutedCommand CancelCommand = new RoutedCommand();
		#endregion

		#region Class Event declarations
		#endregion

		#region Class Variable declarations
		#endregion

		#region Class Constructors & Destructors
		/// <summary>
		/// Class Constructor
		/// </summary>
		public CratosProjectView()
		{
			// Initialize the relevant component(s)
			InitializeComponent();
		}
		#endregion

		#region Class Properties
		/// <summary>
		/// Presenter
		/// </summary>
		public CratosProjectPresenter Presenter
		{
			get { return (this.DataContext as CratosProjectPresenter); }
			set
			{
				// Save the relevant data
				this.DataContext = value;

				// Subscribe to the relevant events
				this.Presenter.ProgressStart	+= new MVPProgressEvent(this.OnProgressStart);
				this.Presenter.ProgressEnd		+= new MVPProgressEvent(this.OnProgressEnd);
				this.Presenter.ProgressUpdate += new MVPProgressUpdateEvent(this.OnProgressUpdate);
			}
		}
		#endregion

		#region Class Methods
		#region Command Event Handlers
		private void OnModifyCommandExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			// Declare the required variables

			// Start the modification
			if (this.DataContext != null) {  this.Presenter.Modify(); }

			// Return to calling method
			return;
		}

		private void OnDeleteCommandExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			// Declare the required variables

			// Delete the current item
			if (this.DataContext != null) { this.Presenter.Cancel(); }

			// Return to calling method
			return;
		}

		private void OnSaveCommandExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			// Declare the required variables

			// Save all pending changes
			if (this.DataContext != null) { this.Presenter.Cancel(); }

			// Return to calling method
			return;
		}

		private void OnCancelCommandExecuted(object sender, ExecutedRoutedEventArgs e)
		{
			// Declare the required variables

			// Cancel all pending changes
			if (this.DataContext != null) { this.Presenter.Cancel(); }

			// Return to calling method
			return;
		}
		#endregion

		private void OnProgressStart()
		{
			// Declare the required variables

			// Display the Progress Message
			//this.m_BorderProgress.Visibility = Visibility.Visible;
			//this.m_LblProgress.Visibility = Visibility.Visible;
			CratosWPFHelper.DoEvents();

			// Return to calling method
			return;
		}

		private void OnProgressEnd()
		{
			// Declare the required variables

			// Display the Progress Message
			//this.m_BorderProgress.Visibility = Visibility.Hidden;
			//this.m_LblProgress.Visibility = Visibility.Hidden;
			CratosWPFHelper.DoEvents();

			// Return to calling method
			return;
		}

		private void OnProgressUpdate(string progressMessage)
		{
			// Declare the required variables

			// Display the Progress Message
			//this.m_LblProgress.Text = progressMessage;
			CratosWPFHelper.DoEvents();

			// Return to calling method
			return;
		}
		#endregion

		#region Class Support Methods
		#endregion
	}
}
